	jQuery(function($) {
		{if $menu != 'main'}
		{/if}

		{if $menu == 'main'}

		{/if}

		{if $menu == 'contract_list'}
		{section name=contract loop=$contract}
		$("#view_{$contract[contract][0]}").click(function(){
		$("#dialog_view_{$contract[contract][0]}").dialog({literal}{width: '80%', modal: true});
		});

		$("#nview_{$contract[contract][0]}").click(function(){
		$("#dialog_view_{$contract[contract][0]}").dialog({literal}{width: '80%', modal: true});
		});

		$("#dialog_view_{$contract[contract][0]}").on( "dialogclose", function( event, ui ){
		$("#display_status1_{$contract[contract][0]}").load('ajax?get=contract&do=status&id={$contract[contract][0]}&display=1').hide().fadeIn("slow");
		});

		$("#edit_{$contract[contract][0]}").click(function(){
		$("#dialog_edit_{$contract[contract][0]}").dialog({literal}{width: '95%', modal: true});
		});

		$("#close_{$contract[contract][0]}").click(function(){
		$("#dialog_edit_{$contract[contract][0]}").dialog("close");
		});

		$("#delete_{$contract[contract][0]}").on(ace.click_event, function() {
		bootbox.confirm("Có chắc chắn?", function(result) {
		if(result) {
		$.ajax({
		url: 'ajax?get=contract&do=delete',
		data: 'id={$contract[contract][0]}',
		type: "POST",
		success: function(json) {
		$("#contract").load('contract?do=list&page={$contract_page_curr}&get=table').hide().fadeIn("slow");
		}
		});
		}
		});
		});

		var datebb_{$contract[contract][0]} = $('#datebb_{$contract[contract][0]}').datepicker({literal}{autoclose:true});
		datebb_{$contract[contract][0]}.on('changeDate', function(ev){
		$.ajax({
		url: 'ajax?get=contract&do=datebb',
		data: 'id={$contract[contract][0]}&value='+ev.date.valueOf(),
		type: "POST"
		});
		});
		datebb_{$contract[contract][0]}.next().on(ace.click_event, function(){
		$(this).prev().focus();
		});

		$('#date_{$contract[contract][0]}').datepicker({literal}{autoclose:true}).next().on(ace.click_event, function(){
		$(this).prev().focus();
		});

		var count_{$contract[contract][0]} = {$contract[contract][11]};
		$('#addmore_{$contract[contract][0]}').click(function(){
		count_{$contract[contract][0]}++;
		var clonedRow_{$contract[contract][0]} = '		<td align="center"><b>'+count_{$contract[contract][0]}+'</b></td>';
		clonedRow_{$contract[contract][0]} += '			<td align="left">';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">';
		clonedRow_{$contract[contract][0]} += '					Sản phẩm: <input id="product_name_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="product_name[]" value="" size="35">';
		clonedRow_{$contract[contract][0]} += '					<select name="product_page[]">{for $foo=1 to 10}<option value="{$foo}">{$foo}</option>{/for}</select> liên';
		clonedRow_{$contract[contract][0]} += '				</span><br>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Mẫu số: <input id="form_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="form[]" value="" size="15"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Ký hiệu: <input id="serial_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="serial[]" value="" size="15"></span><br>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Logo: <label id="logo_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="logo[]" id="logo_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" /> <span class="lbl"></span></label><input type="hidden" id="logo_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" name="logo[]" value="0" /></span>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Hoa văn: <label id="hoavan_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="hoavan[]" id="hoavan_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" /> <span class="lbl"></span></label><input type="hidden" id="hoavan_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" name="hoavan[]" value="0" /></span>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Chống ký: <label id="signed_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="signed[]" id="signed_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" /> <span class="lbl"></span></label><input type="hidden" id="signed_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" name="signed[]" value="0" /></span>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Mật mã: <label id="matma_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="matma[]" id="matma_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" /> <span class="lbl"></span></label><input type="hidden" id="matma_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" name="matma[]" value="0" /></span>';
		clonedRow_{$contract[contract][0]} += '			</td>';
		clonedRow_{$contract[contract][0]} += '			<td align="left">';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Số màu: <select name="color[]">{for $foo=1 to 10}<option value="{$foo}">{$foo}</option>{/for}</select> màu</span><br>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Ruột:<select name="bowel[]"><option value="baibang">Bãi Bằng</option><option value="cacbon">Cacbon</option><option value="offset">Offset</option></select></span><br>';
		clonedRow_{$contract[contract][0]} += '				<span class="inline">Kích thước: <input type="text" name="size[]" value="" size="10"></span>';
		clonedRow_{$contract[contract][0]} += '			</td>';
		clonedRow_{$contract[contract][0]} += '			<td align="center">';
		clonedRow_{$contract[contract][0]} += '				<select name="unit[]"><option value="quyen50">Quyển(50 số)</option><option value="quyen100">Quyển(100 số)</option><option value="so">Số</option><option value="thung">Thùng</option><option value="to">Tờ</option></select>';
		clonedRow_{$contract[contract][0]} += '			</td>';
		clonedRow_{$contract[contract][0]} += '			<td align="center"><input style="text-align:right" id="quantity_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="quantity[]" class="money" value="" size="5"></td>';
		clonedRow_{$contract[contract][0]} += '			<td align="center"><input style="text-align:right" id="quantity_t_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="quantity_t[]" value="" size="5"></td>';
		clonedRow_{$contract[contract][0]} += '			<td align="center"><input style="text-align:right" id="quantity_d_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="quantity_d[]" value="" size="5"></td>';
		clonedRow_{$contract[contract][0]} += '			<td align="right"><input style="text-align:right" id="price_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="text" name="price[]" class="money" value="" size="10"></td>';
		var appendRow_{$contract[contract][0]} = '<tr id="tr_{$contract[contract][0]}">' + clonedRow_{$contract[contract][0]} + '</tr>';
		$('#addtable_{$contract[contract][0]} tr:last').after(appendRow_{$contract[contract][0]});

		$('#logo_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').change(function(){
		if($(this).prop('checked')){
		$('#logo_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').remove();
		}
		else{
		$('#logo_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').after('<input id="logo_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="hidden" name="logo[]" value="0">');
		}
		});
		$('#hoavan_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').change(function(){
		if($(this).prop('checked')){
		$('#hoavan_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').remove();
		}
		else{
		$('#hoavan_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').after('<input id="hoavan_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="hidden" name="hoavan[]" value="0">');
		}
		});
		$('#signed_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').change(function(){
		if($(this).prop('checked')){
		$('#signed_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').remove();
		}
		else{
		$('#signed_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').after('<input id="signed_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="hidden" name="signed[]" value="0">');
		}
		});
		$('#matma_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').change(function(){
		if($(this).prop('checked')){
		$('#matma_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').remove();
		}
		else{
		$('#matma_lbl_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}').after('<input id="matma_hidden_'+count_{$contract[contract][0]}+'_{$contract[contract][0]}" type="hidden" name="matma[]" value="0">');
		}
		});
		});

		$("#submit_edit_{$contract[contract][0]}").click(function(){
		var content;
		$("input").removeClass('input-error');
		$("#form_edit_{$contract[contract][0]}").submit(function(){
		var postData = $(this).serializeArray();
		$.ajax({
		url: 'ajax?get=contract&do=update',
		data: postData,
		type: "POST",
		success: function(data){
		if(data.return == true){
		$("#dialog_edit_{$contract[contract][0]}").dialog("destroy");
		$("#contract").load('contract?do=list&page={$contract_page_curr}&get=table').hide().fadeIn("slow");
		}
		else{
		$('.progressbar').hide();
		content = data.return;
		$("#"+content+"_{$contract[contract][0]}").attr('class', 'input-error');
		}
		}
		});
		}).submit();
		});

		$('#niemphong_{$contract[contract][0]}').change(function(){
		if($(this).prop('checked')){
		$('#niemphong_hidden_{$contract[contract][0]}').remove();
		}
		else{
		$('#niemphong_{$contract[contract][0]}').after('<input id="niemphong_hidden_{$contract[contract][0]}" type="hidden" name="niemphong" value="0">');
		}
		});

		{section name=product loop=$product}
		{if $product[product][1] == $contract[contract][0]}
		$('#logo_{$contract[contract][0]}_{$product[product][0]}').change(function(){
		if($(this).prop('checked')){
		$('#logo_hidden_{$contract[contract][0]}_{$product[product][0]}').remove();
		}
		else{
		$('#logo_lbl_{$contract[contract][0]}_{$product[product][0]}').after('<input id="logo_hidden_{$contract[contract][0]}_{$product[product][0]}" type="hidden" name="logo[]" value="0">');
		}
		});
		$('#hoavan_{$contract[contract][0]}_{$product[product][0]}').change(function(){
		if($(this).prop('checked')){
		$('#hoavan_hidden_{$contract[contract][0]}_{$product[product][0]}').remove();
		}
		else{
		$('#hoavan_lbl_{$contract[contract][0]}_{$product[product][0]}').after('<input id="hoavan_hidden_{$contract[contract][0]}_{$product[product][0]}" type="hidden" name="hoavan[]" value="0">');
		}
		});
		$('#signed_{$contract[contract][0]}_{$product[product][0]}').change(function(){
		if($(this).prop('checked')){
		$('#signed_hidden_{$contract[contract][0]}_{$product[product][0]}').remove();
		}
		else{
		$('#signed_lbl_{$contract[contract][0]}_{$product[product][0]}').after('<input id="signed_hidden_{$contract[contract][0]}_{$product[product][0]}" type="hidden" name="signed[]" value="0">');
		}
		});
		$('#matma_{$contract[contract][0]}_{$product[product][0]}').change(function(){
		if($(this).prop('checked')){
		$('#matma_hidden_{$contract[contract][0]}_{$product[product][0]}').remove();
		}
		else{
		$('#matma_lbl_{$contract[contract][0]}_{$product[product][0]}').after('<input id="matma_hidden_{$contract[contract][0]}_{$product[product][0]}" type="hidden" name="matma[]" value="0">');
		}
		});
		{/if}
		{/section}
		{/section}

		$("select#contract_display").change(function(){
		var str = "";
		$("select#contract_display option:selected").each(function() {
		str = $( this ).text();
		});
		$.ajax({
		url: 'ajax?get=contract&do=display',
		data: 'number='+str,
		type: "POST",
		success: function(json) {
		$("#contract").load('contract?do=list&page={$contract_page_curr}&get=table').hide().fadeIn("slow");
		}
		});
		});
		$("input#search").keyup(function(e){
		if(e.keyCode == 13){
		var str = $(this).val();
		str = str.replace(/&/g, "%26");
		str = str.replace(/ /g, "%20");
		$.ajax({
		success: function(json) {
		var uri = 'contract?do=list&page={$contract_page_curr}&get=table&search='+str;
		$("#contract").load(uri).hide().fadeIn("slow");
		}
		});
		}
		});
		{/if}

		{if $menu == 'contract_add'}
		$( "#marketing" ).autocomplete({
		source: [{section name=mk loop=$marketing}"{$marketing[mk]}",{/section} ]
		});
		var count_add = 1;
		$('#addmore').click(function(){
		count_add++;
		var clonedRow = '<td align="center"><b>'+count_add+'</b><br><br><a id="del_'+count_add+'" style="cursor:pointer">xóa</a></td><td align="left"><span class="inline">Sản phẩm: <input type="text" id="product_name_'+count_add+'" name="product_name[]" size="28" value="Hóa đơn GTGT"><select name="product_page[]">{for $foo=1 to 10}<option value="{$foo}" {if $foo == 3}selected{/if}>{$foo}</option>{/for}</select> liên</span><br><span class="inline">Mẫu số: <input id="form_'+count_add+'" type="text" name="form[]" size="13" onblur="javascript:{literal}{this.value = this.value.toUpperCase(); }" value="01GTKT3/001"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="inline">Ký hiệu: <input id="serial_'+count_add+'" type="text" name="serial[]" size="13" onblur="javascript:{literal}{this.value = this.value.toUpperCase(); }" value="AA/{$year}P"></span><br><span class="inline">Logo: <label id="logo_lbl_'+count_add+'"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="logo[]" id="logo_'+count_add+'" /> <span class="lbl"></span></label></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="inline">Hoa văn: <label id="hoavan_lbl_'+count_add+'"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="hoavan[]" id="hoavan_'+count_add+'" /> <span class="lbl"></span></label></span><br><span class="inline">Chống ký: <label id="signed_lbl_'+count_add+'"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="signed[]" id="signed_'+count_add+'" /> <span class="lbl"></span></label></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="inline">Mật mã: <label id="matma_lbl_'+count_add+'"><input class="ace ace-switch ace-switch-3" type="checkbox" value="1" name="matma[]" id="matma_'+count_add+'" /> <span class="lbl"></span></label></span></td><td align="left"><span class="inline">Số màu: <select name="color[]">{for $foo=1 to 10}<option value="{$foo}">{$foo}</option>{/for}</select></span><br><span class="inline">Ruột:<select name="bowel[]"><option value="baibang">Bãi Bằng</option><option value="cacbon" selected>Cacbon</option><option value="offset">Offset</option></select></span><br><span class="inline">Kích thước: <input type="text" name="size[]" size="10" value="210 x 297mm"></span></td><td align="center"><select name="unit[]"><option value="quyen50" selected>Quyển(50 số)</option><option value="quyen100">Quyển(100 số)</option><option value="so">Số</option><option value="thung">Thùng</option><option value="to">Tờ</option></select></td><td align="center"><input id="quantity_'+count_add+'" type="text" name="quantity[]" size="5" class="money" style="text-align:right"></td><td align="center"><input id="quantity_t_'+count_add+'" type="text" name="quantity_t[]" size="6" style="text-align:right"></td><td align="center"><input id="quantity_d_'+count_add+'" type="text" name="quantity_d[]" size="6" style="text-align:right"></td><td align="center"><input id="price_'+count_add+'" type="text" name="price[]" size="10" class="money" style="text-align:right"></td>';
		var appendRow = '<tr id="tr_'+count_add+'">' + clonedRow + '</tr>';
		$('#contract_addtable tr:last').after(appendRow);
		{for $foo=1 to 10}
		$('#del_{$foo}').click(function(){
		$('#tr_{$foo}').remove();
		count_add = 1;
		});
		{/for}
		});


		$('#date').datepicker({literal}{autoclose:true}).next().on(ace.click_event, function(){
		$(this).prev().focus();
		});

		{if $error == 'tax'}
		alert('Mã số thuế không đúng!');
		$("#tax").attr("class", "input-error");
		{/if}
		{if $success}
		alert('Nhập thành công!');
		{/if}
		{/if}

		{if $menu == 'statistic'}
		$('#tktungay').datepicker({literal}{autoclose:true}).next().on(ace.click_event, function(){
		$(this).focus();
		});
		$('#tkdenngay').datepicker({literal}{autoclose:true}).next().on(ace.click_event, function(){
		$(this).focus();
		});
		{/if}

		{if $menu == 'cover_list'}
		{section name=cover loop=$cover}
		$("#cview_{$cover[cover][0]}").click(function(){
		$("#dialog_cview_{$cover[cover][0]}").dialog({literal}{width: '80%', modal: true});
		});
		{/section}

		$("select#cover_display").change(function(){
		var str = "";
		$("select#cover_display option:selected").each(function() {
		str = $( this ).text();
		});
		$.ajax({
		url: 'ajax?get=cover&do=display',
		data: 'number='+str,
		type: "POST",
		success: function(json) {
		$("#cover").load('cover?do=list&page={$contract_page_curr}&get=table').hide().fadeIn("slow");
		}
		});
		});

		$("input#search").keyup(function(e){
		if(e.keyCode == 13){
		var str = $(this).val();
		str = str.replace(/&/g, "%26");
		str = str.replace(/ /g, "%20");
		$.ajax({
		success: function(json) {
		var uri = 'cover?do=list&page={$contract_page_curr}&get=table&search='+str;
		$("#cover").load(uri).hide().fadeIn("slow");
		}
		});
		}
		});

		{section name=cover loop=$cover}
		$("#close_{$cover[cover][0]}").click(function(){
		$("#dialog_cview_{$cover[cover][0]}").dialog("close");
		});
		{/section}
		{/if}

		})
